#include "register.h"
#include "ui_register.h"
#include "sqlcontroller.h"
#include <QButtonGroup>
#include <QMessageBox>
#include "maincontroller.h"
#include "usermanagement.h"
Register::Register(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Register)
{
    ui->setupUi(this);
    this->setWindowTitle("注册界面");
    QButtonGroup* group = new QButtonGroup(this);
    group->addButton(ui->radioButton);
    group->addButton(ui->radioButton_2);
}

Register::~Register()
{
    delete ui;
}

void Register::on_pushButton_2_clicked()
{
    this->close();
}


void Register::on_pushButton_clicked()
{   QString username = ui->username_lineEdit->text();
    QString password = ui->password_lineEdit->text();
    bool ret = SqlController::getSqlController()->goRegister(username,password,role);
    if(ret){
         QMessageBox::information(this,"注册结果","注册成功！");
          this->close();
         MainController::getMainController()->showUserManagement();


    } else {
         QMessageBox::information(this,"注册结果","注册失败！");
    }

}


void Register::on_radioButton_clicked()
{
    role = 0;
}


void Register::on_radioButton_2_clicked()
{
    role = 1;
}

